package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "设备")
@Slf4j
@RestController
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @ApiOperation("获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult getStationInfo(@PathVariable("gunId") Integer gunId){
        log.info("获取场站信息-{}",gunId);
        StationInfoVO stationInfoVO=new StationInfoVO();
        stationInfoVO.setStationId(123);
        stationInfoVO.setOperatorId(456);
        return JsonResult.ok(stationInfoVO);
    }

    @ApiOperation("更新枪状态")
    @PostMapping("/device/station/gun/status")
    public JsonResult updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam){
        log.info("更新枪的状态-{}",gunStatusUpdateParam);
        Integer gunId = gunStatusUpdateParam.getId();
        Integer gunStatus=gunStatusUpdateParam.getStatus();
        deviceService.DeviceUpdateGunId2Order(gunId,gunStatus);
        return JsonResult.ok(true);
    }

    @ApiOperation("获取所有场站")
    @GetMapping("/station/near")
    public JsonResult getNearStations(Double longitude, Double latitude,Double radius){
        List<StationInfoVO> stationInfoVOList=deviceService.getNearStations(longitude,latitude,radius);
        return JsonResult.ok(stationInfoVOList);
    }

    @ApiOperation("获取站详情")
    @GetMapping("/station/detail/{id}")
    public JsonResult getStationDetail(@PathVariable("id") Integer id){
        StationInfoVO stationInfoVO=deviceService.geStationDetail(id);
        return JsonResult.ok(stationInfoVO);
    }
}
